package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.customer.CustomerDto;
import com.qk.dto.customer.CustomerListDto;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;


    @PutMapping
    public Result updateCustomerInfoById(@RequestBody Customer customer){
        customer.setUpdateTime(LocalDateTime.now());
        customerService.updateById( customer);
        return Result.success();
    }




    @GetMapping("/{id}")
    public Result getCustomerInfoById(@PathVariable Integer id){
        Customer customer = customerService.getCustomerInfoById(id);
        return Result.success(customer);
    }



    @PostMapping
    public Result addCustomer(@RequestBody CustomerDto dto){
        customerService.addCustomer(dto);
        return Result.success();
    }


    @GetMapping
    public Result list(CustomerListDto dto){
        PageResult pageResult = customerService.list(dto);
        return Result.success(pageResult);
    }


}
